import { HttpClient } from '@angular/common/http';
import { MapType } from '@angular/compiler';
import { Injectable } from '@angular/core';
import { Observable } from "rxjs";

@Injectable({
  providedIn: 'root'
})
export class GameManageService {

  // tablelist--URL
  public gameListUrl = '/gameApp/list';

  // 添加游戏
  public addGameUrl = '/gameApp/save';

  // 修改
  public updateGameUrl = '/gameApp/update';

  // 移动
  public moveGameUrl = '/gameApp/move';

  // 文件上传
  public uploadFileUrl = '/common/upload/file';

  constructor(public httpClient: HttpClient) { }

  /**
   * 查询tabledata
   * @param params 
   * @returns 
   */
  public gameTableData(params: any): Promise<any> {
    return this.httpClient.post(this.gameListUrl, params).toPromise();
  }

  /**
   * 添加游戏
   * @param params 
   * @returns 
   */
  public addGameItemData(params: any) {
    return this.httpClient.post(this.addGameUrl, params).toPromise();
  }

  /**
   * 修改游戏
   * @param params 
   * @returns 
   */
  public updateGameInfo(params: any) {
    return this.httpClient.post(this.updateGameUrl, params).toPromise();
  }

  /**
   * 移动排序
   * @param params 
   * @returns 
   */
  public moveTableItem(params: any) {
    return this.httpClient.post(this.moveGameUrl, params).toPromise();
  }

  /**
   * 文件上传
   * @param fileToUpload 
   * @returns 
   */
  public uploadFileData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "game-manage");
    return this.httpClient.post(this.uploadFileUrl, formData).toPromise();
  }
}

